from flask import Flask
from app.config import Config
from app.extensions import db, init_app
from flask_migrate import Migrate
import pymysql

pymysql.install_as_MySQLdb()
migrate = Migrate()

def create_app(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(config_class)
    
    # 初始化所有扩展
    init_app(app)
    
    # 初始化数据库迁移
    migrate.init_app(app, db)
    
    # 注册蓝图
    from app.api.v1 import bp as api_v1_bp
    from app.api.auth import bp as auth_bp
    
    app.register_blueprint(api_v1_bp, url_prefix='/api/v1')
    app.register_blueprint(auth_bp, url_prefix='/api/auth')
    
    return app 